﻿<!-- #include file="../Include/Admin_Onlogin.asp" -->
<%
Dim sqlAuth, rsAuth, PurviewID
sqlAuth = "Select AuthID From Admin_Auth Where href='Admin/Admin_Replace.asp' Order By sort Asc,AuthID Asc"
Call Exec(rsAuth,sqlAuth,2)
If rsAuth.BOF And rsAuth.EOF Then
	PurviewID = 0
Else
	PurviewID = rsAuth(0)
	CheckPurview PurviewID,0
End If
rsAuth.Close
Set rsAuth = Nothing
Select Case Action
Case "load"
    Call loaddb()
Case "do"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='Replace/Update' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,1
	Else
		CheckPurview rsAuth(0),0
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call dodb()
Case Else
    Call Main()
End Select
If FoundErr = True Then
	Call WriteErrMsg(ErrMsg, ComeUrl)
End If
Call CloseConn()

Sub Main()
	Response.Write "<!DOCTYPE html>" & vbCrLf
	Response.Write "<head>" & vbCrLf
	Response.Write "<title>批量替换</title>" & vbCrlf
	Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" & vbCrLf
	Response.Write "<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1'>" & vbCrLf
	Response.Write "<meta name='apple-mobile-web-app-status-bar-style' content='black'>" & vbCrLf
	Response.Write "<meta name='apple-mobile-web-app-capable' content='yes'>" & vbCrLf
	Response.Write "<meta name='format-detection' content='telephone=no'>" & vbCrLf
	Response.Write "<link rel=""stylesheet"" type=""text/css"" href=""../fonts/font-awesome/css/font-awesome.min.css"" />" & vbCrLf
	Response.Write "<link href='../Plugins/layui/css/layui.css' rel='stylesheet' type='text/css' />" & vbCrLf
	Response.Write "<link rel=""stylesheet"" href=""../Style/global.css"" media=""all"">" & vbCrLf
	Response.Write "<link rel=""stylesheet"" href=""../Style/font.css"" media=""all"">" & vbCrLf
	Response.Write "<script type='text/javascript'>" & vbCrLf
	Response.Write "var pc_file = '" & InstallDir & "';" & vbCrLf
	Response.Write "var admin_file = '" & AdminFolder & "/';" & vbCrLf
	Response.Write "</script>" & vbCrLf
	Response.Write "<script type='text/javascript' src='../Js/Admin.js'></script>" & vbCrLf
	Response.Write "<script type='text/javascript' src='../../Dialog/main.js'></script>" & vbCrLf
	Response.Write "<script type='text/javascript' src='../../Dialog/lhgcore.min.js'></script>" & vbCrLf
	Response.Write "<script type='text/javascript' src='../../Dialog/lhgcalendar.min.js'></script>" & vbCrLf
	Response.Write "<script>" & vbCrLf
	Response.Write "function CheckSubmit(){" & vbCrLf
	Response.Write "    if(document.myform.t0.value==''){" & vbCrLf
	Response.Write "        IsAlertFocus('数据表名不能为空！','t0');" & vbCrLf
	Response.Write "        return false;" & vbCrLf
	Response.Write "    }" & vbCrLf
	Response.Write "    if(document.myform.t3.value==''){" & vbCrLf
	Response.Write "        IsAlertFocus('将字符不能为空！','t3');" & vbCrLf
	Response.Write "        return false;" & vbCrLf
	Response.Write "    }" & vbCrLf
	Response.Write "}" & vbCrLf
	Response.Write "function getfield(t0){" & vbCrLf
	Response.Write "    $.ajax({" & vbCrLf
	Response.Write "        type: ""get""," & vbCrLf
	Response.Write "        cache:false," & vbCrLf
	Response.Write "        url:""?Action=load&t0=""+escape(t0)," & vbCrLf
	Response.Write "        error:function(){}," & vbCrLf
	Response.Write "        success: function(_){$('#wangkaicms').html(_);}" & vbCrLf
	Response.Write "    });" & vbCrLf
	Response.Write "}" & vbCrLf
	Response.Write "</script>" & vbCrLf
	Response.Write "</head>" & vbCrlf
	Response.Write "<body>" & vbCrlf
	Response.Write "<form class='layui-form layui-form-pane' id=""myform"" name=""myform"" method=""post"" action=""?Action=do"" target=""plug"" onSubmit='return CheckSubmit();'>" & vbCrLf
	Response.Write "<div class=""admin-main fadeInUp animated"">" & vbCrLf
	Response.Write "    <fieldset class=""layui-elem-field layui-field-title"">" & vbCrLf
	Response.Write "        <legend>批量替换</legend>" & vbCrLf
	Response.Write "    </fieldset>" & vbCrLf
	Response.Write "    <div class=""layui-form-item"">" & vbCrLf
	Response.Write "        <label class=""layui-form-label"">数据表名：</label>" & vbCrLf
	Response.Write "        <div class=""layui-input-4"">" & vbCrLf
	Response.Write "            <div id=""t0_outer"" ztype=""select"" class=""z-combox"" style=""display:inline-block; *zoom: 1;*display: inline;vertical-align:middle;height:auto;width:auto;position:relative;border:none 0;margin:0;padding:0;white-space: nowrap;"" _style=""width:100%;""><input type=""text"" ztype=""select"" id=""t0"" name=""t0"" tabindex=""-1"" autocomplete=""off"" class=""inputText"" style=""width:100%;position:absolute;z-index:-1;"" onChange=""if(this.value!='')getfield(this.value)"" value="""" startvalue="""" lay-verify=""t0""/><input type=""text"" id=""t0_textField"" autocomplete=""off"" class=""inputText"" style=""vertical-align:middle; cursor:default;width:100%;"" /><a id=""t0_spinner"" class=""z-combox-spinner"" style=""position:relative; left:-17px; margin-right:-15px; cursor:pointer; width:13px; height:15px;vertical-align:middle;""><b></b></a><div id=""t0_list"" class=""optgroup"" style=""text-align:left;display:none;""><div id=""t0_ul"" style=""left:-1px; width:-1px;""><script>Combox_t0_Init=function(){var _el=Zving.getDom('t0');if(_el._components){return true;}var  _data=[];var  _DataSource;"
	Response.Write "_data.push(['','请选择']);"
	set rsSchema=Conn.OpenSchema(20)
	rsSchema.movefirst
	While not rsSchema.EOF
		If rsSchema("TABLE_TYPE")="TABLE" Then
			If rsSchema("Description")<>"" Then
				Response.Write "_data.push(['"&rsSchema("TABLE_NAME")&"','"&rsSchema("TABLE_NAME")&" ("&rsSchema("Description")&")']);"
			Else
				Response.Write "_data.push(['"&rsSchema("TABLE_NAME")&"','"&rsSchema("TABLE_NAME")&"']);"
			End If
		End If
		rsSchema.movenext
	Wend
	Response.Write "var combox_t0 = new Zving.Selector({el:_el,data:_data,DataSource:_DataSource});};if(Zving.Page.isReady){Combox_t0_Init();}else{Zving.Page.onReady(Combox_t0_Init);}</script></div></div></div>" & vbCrLf
	Response.Write "        </div>" & vbCrLf
	Response.Write "    </div>" & vbCrLf
	Response.Write "    <div class=""layui-form-item"">" & vbCrLf
	Response.Write "        <label class=""layui-form-label"">字段名：</label>" & vbCrLf
	Response.Write "        <div class=""layui-input-4"" id=""wangkaicms"">" & vbCrLf
	Response.Write "            <div id=""t1_outer"" ztype=""select"" class=""z-combox"" style=""display:inline-block; *zoom: 1;*display: inline;vertical-align:middle;height:auto;width:auto;position:relative;border:none 0;margin:0;padding:0;white-space: nowrap;"" _style=""width:100%;""><input type=""text"" ztype=""select"" id=""t1"" name=""t1"" tabindex=""-1"" autocomplete=""off"" class=""inputText"" style=""width:100%;position:absolute;z-index:-1;"" onChange=""if(this.value!='')getfield(this.value)"" value="""" startvalue="""" lay-verify=""t1""/><input type=""text"" id=""t1_textField"" autocomplete=""off"" class=""inputText"" style=""vertical-align:middle; cursor:default;width:100%;"" /><a id=""t1_spinner"" class=""z-combox-spinner"" style=""position:relative; left:-17px; margin-right:-15px; cursor:pointer; width:13px; height:15px;vertical-align:middle;""><b></b></a><div id=""t1_list"" class=""optgroup"" style=""text-align:left;display:none;""><div id=""t1_ul"" style=""left:-1px; width:-1px;""><script>Combox_t1_Init=function(){var _el=Zving.getDom('t1');if(_el._components){return true;}var  _data=[];var  _DataSource;_data.push(['','请选择']);var combox_t1 = new Zving.Selector({el:_el,data:_data,DataSource:_DataSource});};if(Zving.Page.isReady){Combox_t1_Init();}else{Zving.Page.onReady(Combox_t1_Init);}</script></div></div></div>" & vbCrLf
	Response.Write "        </div>" & vbCrLf
	Response.Write "    </div>" & vbCrLf
	Response.Write "    <div class=""layui-form-item"">" & vbCrLf
	Response.Write "        <label class=""layui-form-label"">替换数量：</label>" & vbCrLf
	Response.Write "        <div class=""layui-input-4"">" & vbCrLf
	Response.Write "            <input id=""t2"" name=""t2"" type=""number"" min=""0"" value=""0"" maxlength=""5"" class=""layui-input"">" & vbCrLf
	Response.Write "        </div>" & vbCrLf
	Response.Write "        <div class=""layui-form-mid layui-word-aux"">为0时替换全部</div>" & vbCrLf
	Response.Write "    </div>" & vbCrLf
	Response.Write "    <div class=""layui-form-item layui-form-text"">" & vbCrLf
	Response.Write "        <label class=""layui-form-label"">将字符：</label>" & vbCrLf
	Response.Write "        <div class=""layui-input-block"">" & vbCrLf
	Response.Write "            <textarea id=""t3"" name=""t3"" rows=""4"" class=""layui-textarea""></textarea>" & vbCrLf
	Response.Write "        </div>" & vbCrLf
	Response.Write "    </div>" & vbCrLf
	Response.Write "    <div class=""layui-form-item layui-form-text"">" & vbCrLf
	Response.Write "        <label class=""layui-form-label"">替换为：</label>" & vbCrLf
	Response.Write "        <div class=""layui-input-block"">" & vbCrLf
	Response.Write "            <textarea id=""t4"" name=""t4"" rows=""4"" class=""layui-textarea""></textarea>" & vbCrLf
	Response.Write "        </div>" & vbCrLf
	Response.Write "    </div>" & vbCrLf
	Response.Write "    <div class=""layui-form-item"">" & vbCrLf
	Response.Write "        <div class=""layui-input-block"">" & vbCrLf
	Response.Write "            <button type=""submit"" class=""layui-btn"" accesskey=""s"">执行</button>" & vbCrLf
	Response.Write "            <button type=""reset"" class=""layui-btn layui-btn-danger"" accesskey=""r"">重置</button>" & vbCrLf
	Response.Write "        </div>" & vbCrLf
	Response.Write "    </div>" & vbCrLf
	Response.Write "    <div class=""layui-form-item layui-form-text"">" & vbCrLf
	Response.Write "        <label class=""layui-form-label"">处理进度：</label>" & vbCrLf
	Response.Write "        <div class=""layui-input-block"">" & vbCrLf
	Response.Write "            <iframe src=""about:blank"" scrolling=""auto"" height=""80"" name=""plug"" frameborder=""0"" style=""width:100%;border:1px solid #e6e6e6;""></iframe>" & vbCrLf
	Response.Write "        </div>" & vbCrLf
	Response.Write "    </div>" & vbCrLf
	Response.Write "</div>" & vbCrLf
	Response.Write "</form>" & vbCrLf
	Response.Write "</body>" & vbCrLf & "</html>"
End Sub

sub loaddb()
	dim t0:t0=Trim(Request("t0"))
	dim str01,str02,str03
	if t0<>"" then
		Set ColumnsSchema = Conn.OpenSchema(4, Array(Empty, Empty, t0))
		Set field = CreateObject("Scripting.Dictionary")
		Set list = CreateObject("Scripting.Dictionary")
		Do While Not ColumnsSchema.EOF
			field.Add ColumnsSchema("ORDINAL_POSITION").Value, ColumnsSchema("COLUMN_NAME").Value
			list.Add ColumnsSchema("ORDINAL_POSITION").Value, ColumnsSchema("Description").Value
			ColumnsSchema.MoveNext
		Loop
		str01="<div id=""t1_outer"" ztype=""select"" class=""z-combox"" style=""display:inline-block; *zoom: 1;*display: inline;vertical-align:middle;height:auto;width:auto;position:relative;border:none 0;margin:0;padding:0;white-space: nowrap;"" _style=""width:100%;""><input type=""text"" ztype=""select"" id=""t1"" name=""t1"" tabindex=""-1"" autocomplete=""off"" class=""inputText"" style=""width:100%;position:absolute;z-index:-1;"" onchange=""changeClassType(this.options[this.selectedIndex].value);"" value=""" & ot1 & """ startvalue=""" & ot1 & """ lay-verify=""t1""/><input type=""text"" id=""t1_textField"" autocomplete=""off"" class=""inputText"" style=""vertical-align:middle; cursor:default;width:100%;"" /><a id=""t1_spinner"" class=""z-combox-spinner"" style=""position:relative; left:-17px; margin-right:-15px; cursor:pointer; width:13px; height:15px;vertical-align:middle;""><b></b></a><div id=""t1_list"" class=""optgroup"" style=""text-align:left;display:none;""><div id=""t1_ul"" style=""left:-1px; width:-1px;""><script>Combox_t1_Init=function(){var _el=Zving.getDom('t1');if(_el._components){return true;}var  _data=[];var  _DataSource;_data.push(['','请选择']);"&vbcrlf
		str03="var combox_t1 = new Zving.Selector({el:_el,data:_data,DataSource:_DataSource});};if(Zving.Page.isReady){Combox_t1_Init();}else{Zving.Page.onReady(Combox_t1_Init);}</script></div></div></div>"
		For i=1 To field.Count
			If list.Item(i)<>"" Then
				str02=str02&"_data.push(['"&field.Item(i)&"','"&field.Item(i)&" ("&list.Item(i)&")']);"
			Else
				str02=str02&"_data.push(['"&field.Item(i)&"','"&field.Item(i)&"']);"
			End If
		Next
		Response.Write str01&str02&str03
	end if
End Sub

sub dodb()
	dim t0,t1,t2,t3,t4
	t0=Code_Form("t0")
	t1=Code_Form("t1")
	t2=Code_CLng(Code_Form("t2"))
	t3=Code_Form("t3")
	t4=Code_Form("t4")
	
	dim rs,i
	dim topstr:topstr=""
	if t1="" then
		t1="*"
	end if
	if t2<>0 then
		topstr="top "&t2
	end if
	on error resume next
	Call Exe_Conn(rs,"select "&topstr&" "&t1&" from "&t0&"",3)
	if rs.eof then
		Response.Write "没有信息可替换"
		exit sub
	end if
	i=0
	do while not rs.eof
		if instr(rs(0),t3)>0 then
			rs(0)=replace(rs(0),t3,t4)
			i=i+1
			if t2<>0 then
				if i>=t2 then
					Response.Write "替换完毕，总计替换了<span>"&i&"</span>条<br>"
					Response.Write "<script>window.scroll(0,99999)</script><br>"
					response.flush()
					exit sub
				end if
			end if
			Response.Write "正在替换第<span>"&i&"</span>条<br>"
			Response.Write "<script>window.scroll(0,99999)</script><br>"
			response.flush()
			rs.update
		end if
	rs.movenext
	loop
	rs.close
	set rs=nothing
	Response.Write "替换完毕，总计替换了<span>"&i&"</span>条<br>"
	Response.Write "<script>window.scroll(0,99999)</script><br>"
	response.flush()
	if err then
		Response.Write "发生错误，错误内容为：<span>"&err.description&"</span><br>"
		Response.Write "<script>window.scroll(0,99999)</script><br>"
	end if
End Sub
%>